package com.jvyou.app.ds.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jvyou.app.common.domain.dto.DictTypeDto;
import com.jvyou.app.common.domain.entity.DictType;
import com.jvyou.app.common.domain.model.PageResult;
import com.jvyou.app.common.utils.orm.WrapperTool;
import com.jvyou.app.ds.mapper.DictTypeMapper;
import com.jvyou.app.ds.service.DictTypeService;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 字典类型表(DictType)表服务实现类
 *
 * @author 橘柚
 * @since 2025-03-13 10:10:11
 */
@Service("dictTypeService")
public class DictTypeServiceImpl extends ServiceImpl<DictTypeMapper, DictType> implements DictTypeService {

    private QueryWrapper<DictType> getWrapper(DictTypeDto dictTypeDto) {
        QueryWrapper<DictType> wrapper = new QueryWrapper<>();
        WrapperTool.notEmptyLike(wrapper, "dict_name", dictTypeDto.getDictName());
        WrapperTool.notEmptyEq(wrapper, "dict_type", dictTypeDto.getDictType());
        WrapperTool.notEmptyEq(wrapper, "status", dictTypeDto.getStatus());
        return wrapper;
    }

    @Override
    public List<DictType> listDictType(DictTypeDto dictTypeDto) {
        return list(getWrapper(dictTypeDto));
    }

    @Override
    public PageResult<DictType> pageDictType(DictTypeDto dictTypeDto) {
        Page<DictType> page = new Page<>(dictTypeDto.getCurrent(), dictTypeDto.getPageSize());
        return PageResult.success(page(page, getWrapper(dictTypeDto)));
    }
}
